/*******************************************************************************
 * 
 * Copyright:
 * 
 * License:
 * 
 * Authors: SALMON Charles
 * 
 ******************************************************************************/

/*******************************************************************************
 * 
 ******************************************************************************/

/**
 * Create a new window to view existing topics
 */
qx.Class.define("bip.ui.topics.WinSearchTopics", 
{
	extend: bip.ui.win.Dialog,

	/*
	*****************************************************************************
	 EVENTS
	*****************************************************************************
	*/  
	events :
	{
		
		
	},

	/*
	*****************************************************************************
	 PROPERTIES
	*****************************************************************************
	*/ 
	properties: {
		
  	},

	/*
	*****************************************************************************
	 CONSTRUCTOR
	*****************************************************************************
	*/
	
	/**
	 * Construct the window
	 */	
 	construct: function()
	{
		this.base(arguments,"Search topics","Search topics",null,"icon/48/actions/system-search.png");
		this.set({
			width: 400,
			height: 0
		});
		
		// SERVICE
		var service = bip.services.SynchronizedTopics.getInstance();
		service.addListener("error",function(evt) {
			this.setStateWithDescription("error",evt.getData().getMessage());
    },this);
		service.addListener("loaded",function(evt) {
			this.setStateWithDescription("ready",this.tr("Find a specific topic"));
    },this);
		service.addListener("loading",function(evt) {
			this.setStateWithDescription("running",this.tr("Fetching topics, please wait..."));
    },this);
	},

	/*
	*****************************************************************************
	 MEMBERS
	*****************************************************************************
	*/	
	members:
	{	
		/**
     * Create the content of the dialog. 
     * Extending classes must implement this method.
     */
    _createWidgetContent : function()
    {
    	this.__createActionBar(this.getChildControl("actionbar"));
  		var groupBox = new qx.ui.groupbox.GroupBox("Topics");
  		groupBox.setLayout(new qx.ui.layout.VBox());
      // TOPICS LIST
  		this.__topicsList = new bip.ui.form.SynchronizedTopicList();
  		this.__topicsList.setHeight(90);
  		groupBox.add(this.__topicsList);
  		this.setLayout(new qx.ui.layout.VBox(5));
    	this.add(groupBox);
    	
    },
    
    
    
    /**
		 * Fill up the controler with the button bar
		 */
		__createActionBar: function(control) {
			var cancelCmd = new qx.ui.core.Command();
			cancelCmd.addListener("execute",this.__onCancelButtonClickHandler,this);
			this.populateActionBar({
				buttons:[
							{id:"close", type:"CloseButton", label: "Close",command:cancelCmd}
						]
			},control);
			//this.setActionBarButtonsProperties({width:80,height:20});
		},
		
		__onCancelButtonClickHandler: function(evt) {
			this.hide();
		},
		
		_beforeShow: function() {
			this.setStateWithDescription("running",this.tr("Fetching topics, please wait..."));
			bip.services.SynchronizedTopics.getInstance().fetchTopics();
	   }
		
	    

		/*
	  	*****************************************************************************
	     UI
	  	*****************************************************************************
	 	*/
		

	},
	/*
	 * ****************************************************************************
	 * DESTRUCTOR
	 * ****************************************************************************
	 */

	destruct : function() {
		this._disposeObjects();
		
	}
	
});
